package com.tiny.work.test.threadlocal;

public class ThreadLocalDemo {

    public static void main(String args[]) throws InterruptedException {
        Thread thread =  new Thread(new MyThreadDemo(new PlexDemo()));
        thread.start();
        Thread.sleep(1000);

        System.gc();
        Thread.sleep(10000);
        System.gc();
        Thread.sleep(10000);
        System.gc();
        Thread.sleep(10000);

    }

}
class MyThreadDemo implements Runnable{
    PlexDemo pluex;

    public MyThreadDemo(PlexDemo pluex) {
        this.pluex = pluex;
    }

    @Override
    public void run() {
        pluex.m_ctx.get();
    }
}

class PlexDemo{
    public ThreadLocal<Context> m_ctx = new ThreadLocal<Context>(){
        @Override
        protected Context initialValue() {
            return new Context();
        }
    };
}

class Context{
    char [] data = new char[1024 * 1024]; //2MB

    public char[] getData() {
        return data;
    }

    public void setData(char[] data) {
        this.data = data;
    }
}